﻿using PosClient.Interfaces;
using PosClient.Model;
using PosClient.ViewModel;
using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Text;
using System.Threading.Tasks;

namespace PosClient.Job.DownLoad
{
    public class BarcodeDownLoadJob : IJob
    {
        public Result<JobEntity> Excute()
        {
            var viewModel = Locator.Current.GetService<MainViewModel>();
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = "正在下载商品多条码数据...";
                viewModel.Loading = true;
            });
            Result<JobEntity> result = new Result<JobEntity>()
            { 
                Success = true,
                Message = "Barcode请求成功"
            };
            List<PluBarcode> BarcodeList = new List<PluBarcode>();
            BarcodeList.Add(new PluBarcode() 
            {
                 Barcode = "599451651892",
                 PluCode = "0002816",
            });
            BarcodeList.Add(new PluBarcode()
            {
                Barcode = "259451651812",
                PluCode = "0002818",
            });
            BarcodeList.Add(new PluBarcode()
            {
                Barcode = "569451651812",
                PluCode = "0002817",
            });
            var server = Locator.Current.GetService<IPluService>();
            server.CacheBarcode(BarcodeList);
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = string.Empty;
                viewModel.Loading = false;
            });
            return result;
        }

    }
}
